<?php
/**
* @file $Id: DrawHeader.fnc.php 489 2007-05-08 14:45:52Z focus-sis $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

function DrawHeader($left='', $right='', $center='', $style='', $b_border=true, $required=false) 
{
	echo ComposeHeader($left, $right, $center, $style, $b_border, $required);
}

function ComposeHeader($left='', $right='', $center='', $style='', $b_border=true, $required=false)
{	global $_FOCUS;
	$s_border = '';
	$stream = '';

	if($_REQUEST['_FOCUS_PDF'] 
	&& $_REQUEST['_template_id'] 
	&& !$style)
	{
		if(!$_FOCUS['DrawHeader']) {
			// Print the template's headers instead of this one
			$stream .= ComposeTemplateHeaders(); 
		}
		if(!$required) {
			// if printing with a template, and this header isn't one of the templates, don't display it
			return; 
		}
	}
	
	if (!isset($_FOCUS['DrawHeader']) 
	&& !$_REQUEST['_FOCUS_PDF'] 
	&& !$style)
	{
		$_FOCUS['DrawHeader'] = 
				'background=assets/themes/'
				.Preferences('THEME')
				.'/bg.jpg';
				
		if(!(
		(User('PROFILE')!='admin' && User('PROFILE')!='teacher') 
		|| Preferences('MENU')=='Top'
		))
		{
			$s_border = 'style="border-width: 2; border-style: inset none none none;"';
		}
		if($_FOCUS['HeaderIcon']) {		
			$left = '<IMG SRC="assets/icons/'
					.$_FOCUS['HeaderIcon']
					.'.png">'
					.'<IMG SRC="assets/pixel_trans.gif" height="1" width="4">'
					.'<font size="+1">'.$left.'</font>';
		}
	}
	elseif (
	(!isset($_FOCUS['DrawHeader']) || $style == 'blue') 
	&& !($style && $style != 'blue')
	) {
		$_FOCUS['DrawHeader'] = 'bgcolor="#333366"';
	}
	elseif ($style == 'white') {
		$_FOCUS['DrawHeader'] = 'bgcolor="#FFFFFF"';		
	}
	elseif ($style == 'gray') {
		$_FOCUS['DrawHeader'] = 'bgcolor="#F0F0F1"';
	}
	
	if($style && $b_border) {
		$_FOCUS['DrawHeader'] .= ' style="border: 1; border-style: none none solid none;"';
	}
	
	if($_FOCUS['DrawHeader'] == 'background="assets/themes/'.Preferences('THEME').'/bg.jpg"') {
		$attribute = 'B';
		$font_color = '000000';
		if(Preferences('THEME') == 'Ocean' 
		|| Preferences('THEME') == 'Wood-Grain' 
		|| Preferences('THEME') == 'Midnight')
		{
			$font_color = 'FFFFFF';
		}
		$font_color .= ' class="BottomButton"';
	}
	elseif($_FOCUS['DrawHeader'] == 'bgcolor="#333366"') {	
		$attribute = 'B';
		$font_color = 'FFFFFF';
	}
	else
	{
		$attribute = 'FONT size=-1';
		$font_color = '333333';
	}
		
	$stream .= '<TABLE width="100%" border="0" cellpadding="0" cellspacing="0" '
			.$s_border.'><TR>';
			
	if($center 
	&& $center != '' 
	&& (
	($left && trim($left) != '') 
	|| ($right && trim(str_replace('&nbsp;', '', $right)) != '')
	)) {
		$width = ' width="33%" ';
	}
	
	if(!$style 
	|| $style == '')
	{
		$space =' &nbsp;';
	}
	
	if($left) {
		$stream .= '<TD '.$_FOCUS['DrawHeader'].$width
				.' align="'.ALIGN_LEFT.'">'
				.$space
				.'<font color="#'.$font_color.'">'
				.'<'.$attribute.'>'
				.$left
				.'</'.substr($attribute,0,4).'>'
				.'</font></TD>';
	}
	if($center) {
		$stream .= '<TD '.$_FOCUS['DrawHeader']
				.$width
				.' align="center">'
				.'<font color="#'.$font_color.'">'
				.'<'.$attribute.'>'
				.$center
				.'</'.$attribute.'>'
				.'</font></TD>';
	}
	if($right) {
		$stream .= '<TD align="'.ALIGN_RIGHT.'" '
				.$_FOCUS['DrawHeader'].$width.'>'
				.'<font color="#'.$font_color.'">'
				.'<'.$attribute.'>'
				.$right
				.'</'.substr($attribute,0,4).'>'
				.'</font></TD>';
	}
	$stream .= '</TR></TABLE>';

	if($_FOCUS['DrawHeader'] == 
			'background="assets/themes/'.Preferences('THEME').'/bg.jpg"' 
	&& !$_REQUEST['_FOCUS_PDF'])
	{
		$_FOCUS['DrawHeader'] = 
				'bgcolor="#FFFFFF" style="border: 1; border-style: none none solid none;"';
		DrawTemplateHeaders();
	}
	elseif($_FOCUS['DrawHeader'] == 'bgcolor="#333366"' 
	&& !($style && $_REQUEST['_FOCUS_PDF']))
	{
		$_FOCUS['DrawHeader'] = 
				'bgcolor="#F0F0F1" style="border: 1; border-style: none none solid none;"';
		//DrawTemplateHeaders();	//I dont know who removed this, when, why, ...  -bl
	}
	else {
		$_FOCUS['DrawHeader'] = 
				'bgcolor="#F0F0F1" style="border: 1; border-style: none none solid none;"';
	}
	return $stream;
}

function DrawTemplateHeaders($studentid='', $type='header')
{
	echo ComposeTemplateHeaders($studentid, $type);
}

function ComposeTemplateHeaders($studentid='', $type='header')
{	global $functions,$student_id;

	$stream = '';
	if($_REQUEST['_template_id']) {
		if(!$studentid 
		&& $student_id)
		{
			$studentid = $student_id;
		}
		if(!$studentid 
		&& $_SESSION['student_id'])
		{
			$studentid = $_SESSION['student_id'];
		}

		$rows_RET = DBGet(DBQuery(
				"SELECT      LEFT_CELL
				 ,           MIDDLE_CELL
				 ,           RIGHT_CELL
				 ,           STYLE
				 ,           BORDER 
				 FROM        HEADER_ROWS 
				 WHERE       TEMPLATE_ID = '".$_REQUEST['_template_id']."' 
				 AND         TYPE = '$type' 
				 ORDER BY    SORT_ORDER"
				));
				
		if($type == 'header') {
			$page_RET = DBGet(DBQuery(
					"SELECT      LEFT_CELL
					 ,           MIDDLE_CELL
					 ,           RIGHT_CELL 
					 FROM        HEADER_ROWS 
					 WHERE       TEMPLATE_ID = '".$_REQUEST['_template_id']."' 
					 AND         TYPE = 'pageh'"
					));
					
			$rows_RET[-1] = $page_RET[1];
			
			$page_RET = DBGet(DBQuery(
					"SELECT      LEFT_CELL
					 ,           MIDDLE_CELL
					 ,           RIGHT_CELL
					 FROM        HEADER_ROWS
					 WHERE       TEMPLATE_ID = '".$_REQUEST['_template_id']."'
					 AND         TYPE = 'pagef'"
					));
			
			$rows_RET[-2] = $page_RET[1];
		}
		foreach($rows_RET as $row) {
			// I dont like this next chunk of code, and I dont dare change it becuase I can see how
			// it might have been intentional.  I'll have to analize the intent and output
			// to fix it up, but it seems that it should be using == and not just =
			if($field = 
			substr($row['LEFT_CELL'], strrpos($row['LEFT_CELL'], '~') + 1)) 
			{
				$fields .= AssignFieldTable($field, $studentid);
			}
			if($field = 
			substr($row['MIDDLE_CELL'], strrpos($row['MIDDLE_CELL'], '~') + 1)) 
			{
				$fields .= AssignFieldTable($field, $studentid);
			}
			if($field = 
			substr($row['RIGHT_CELL'], strrpos($row['RIGHT_CELL'], '~') + 1)) 
			{
				$fields .= AssignFieldTable($field, $studentid);
			}
		}

		if($studentid) {
			if(strpos($fields,',a.') !== false) {
				$extra['FROM'] .= 
						"LEFT OUTER JOIN STUDENTS_JOIN_ADDRESS sam 
						 ON (  ssm.STUDENT_ID = sam.STUDENT_ID "
						       .$extra['STUDENTS_JOIN_ADDRESS']."
						    ) 
						 LEFT OUTER JOIN ADDRESS a 
						 ON    sam.ADDRESS_ID = a.ADDRESS_ID ";
			}
			
			$extra['SELECT_ONLY'] = substr($fields, 0, -1);
			$extra['WHERE'] .= " AND s.STUDENT_ID='$studentid' ";
			$extra['functions'] = $functions;
			$student = GetStuList($extra);
			$student = $student[1];
		}
		else {
			$student['SCHOOL_ID'] = GetSchool(UserSchool());
		}
		// I got to here before I shifted to work on somehting else -BL
		$cells = array('LEFT','RIGHT','MIDDLE');

		foreach($cells as $cell)
		{
			$text = substr($rows_RET[-1][$cell.'_CELL'],0,strrpos($rows_RET[-1][$cell.'_CELL'],'~'));
			$field_value = substr($rows_RET[-1][$cell.'_CELL'],strrpos($rows_RET[-1][$cell.'_CELL'],'~')+1);
			if(substr($field_value,0,1)=='$')
				$text .= $field_value;
			else
				$text .= ereg_replace('<!--[^>]+>','',$student[$field_value]);
			if($text)
				$stream .= '<!-- HEADER '.($cell=='MIDDLE'?'CENTER':$cell).' "'.$text.'" -->';
			$text = substr($rows_RET[-2][$cell.'_CELL'],0,strrpos($rows_RET[-2][$cell.'_CELL'],'~'));
			$field_value = substr($rows_RET[-2][$cell.'_CELL'],strrpos($rows_RET[-2][$cell.'_CELL'],'~')+1);
			if(substr($field_value,0,1)=='$')
				$text .= $field_value;
			else
				$text .= ereg_replace('<!--[^>]+>','',$student[$field_value]);
			if($text)
				$stream .= '<!-- FOOTER '.($cell=='MIDDLE'?'CENTER':$cell).' "'.$text.'" -->';
		}

		$field_value = array();
		unset($rows_RET[-1]);
		unset($rows_RET[-2]);
		$cells = array('LEFT_CELL','RIGHT_CELL','MIDDLE_CELL');

		if(strpos($rows_RET[1]['LEFT_CELL'],'<IMG SRC')!==false && !trim(str_replace('~','',$rows_RET[1]['RIGHT_CELL'])) && !trim(str_replace('~','',$rows_RET[1]['MIDDLE_CELL'])))
		{
			$stream .= '<TABLE width=100%><TR><TD valign=top width=25%>'.substr($rows_RET[1]['LEFT_CELL'],0,strrpos($rows_RET[1]['LEFT_CELL'],'~')).'</TD><TD valign=top>';
			$close_table = true;
			unset($rows_RET[1]);
		}
		foreach($rows_RET as $i=>$row)
		{
			foreach($cells as $cell)
			{
				$start = $end = '';
				$real_text = false;
				$text[$cell] = substr($row[$cell],0,strrpos($row[$cell],'~'));
				$tags = explode(']',$text[$cell]);
				$tags_arr = array('bold'=>'b','italic'=>'i','heading'=>'h3','small'=>'small','underline'=>'u','red'=>'font color=red','blue'=>'font color=blue','white'=>'font color=white','green'=>'font color=green');
				foreach($tags as $tag)
				{
					if(substr($tag,0,1)=='[')
					{
						$tag = substr($tag,1);
						$start .= '<'.$tags_arr[$tag].'>';
						if(strpos($tags_arr[$tag],' '))
							$end_tag = substr($tags_arr[$tag],0,strpos($tags_arr[$tag],' '));
						else
							$end_tag = $tags_arr[$tag];
						$end .= '</'.$end_tag.'>';
					}
					else
					{
						$real_text = true;
						continue;
					}
				}
				if($real_text)
					$text[$cell] = $start.$tag;
				else
					$text[$cell] = $start;
				if(strpos($text[$cell],'<IMG SRC')===false)
					$field_value[$cell] = $student[substr($row[$cell],strrpos($row[$cell],'~')+1)];
				else
					$field_value[$cell] = '';
				$field_value[$cell] .= $end;
				
			}

			if(!$row['STYLE'])
				$row['STYLE'] = 'gray';
			$mid_cell = $text['MIDDLE_CELL'].' '.$field_value['MIDDLE_CELL'];
			if($mid_cell==' ')
				$mid_cell = '';

			// Actually draw the template header.  The border value
			// is taken from the database as a Y or N.  If it is a 
			// Y then pass a TRUE value to the function
			$stream .= ComposeHeader($text['LEFT_CELL'].' '.$field_value['LEFT_CELL'],' &nbsp; '.$text['RIGHT_CELL'].' '.$field_value['RIGHT_CELL'],$mid_cell,$row['STYLE'], $row['BORDER'] === 'Y');
		}
		if($close_table)
			$stream .= '</TD></TR></TABLE>';
	}
	return $stream;
}

function AssignFieldTable($field,$studentid='')
{	global $functions,$_FOCUS,$short_names_RET,$periods_RET;

	if(substr($field,0,1)=='$')
		return;

	if(substr($field,0,7)=='CUSTOM_' && !$_FOCUS['fields_RET'])
		$_FOCUS['fields_RET'] = DBGet(DBQuery("SELECT * FROM CUSTOM_FIELDS"),array(),array('ID'));
	
	if(substr($field,0,7)=='CUSTOM_')
	{
		if(!$studentid)
			return;

		if($_FOCUS['fields_RET'][substr($field,7)][1]['TYPE']=='log')
		{
			$functions[$field] = 'makeLogHeader';
			$field = "'".$studentid."' AS ".$field;
			return $field.',';
		}
		
		if($_FOCUS['fields_RET'][substr($field,7)][1]['TYPE']=='date')
			$functions[$field] = 'ProperDate';
	}

	switch($field)
	{
		case 'STUDENT_ID':
			$field = 's.STUDENT_ID';
		break;
		
		case 'SCHOOL_ID':
			$functions['SCHOOL_ID'] = 'GetSchool';
			$field = 'ssm.SCHOOL_ID';
		break;

		case 'SYEAR':
			$functions['SYEAR'] = 'makeSyear';
			$field = 'ssm.SYEAR';
		break;
		
		case 'GRADE_ID':
			$functions['GRADE_ID'] = 'GetGrade';
			$field = 'ssm.GRADE_ID';
		break;
		
		case 'NEXT_SCHOOL':
			$functions['SCHOOL_ID'] = 'GetSchool';
			$field = 'ssm.NEXT_SCHOOL';
		break;

		case 'CALENDAR_ID':
			$field = 'ssm.CALENDAR_ID';
		break;
		
		case 'FULL_NAME':
			if(Preferences('NAME_FORMAT')=='Y')
				$field = "s.LAST_NAME||', '||s.FIRST_NAME||' '||COALESCE(s.MIDDLE_NAME,' ') AS FULL_NAME";
			else
				$field = "s.FIRST_NAME||' '||COALESCE(s.MIDDLE_NAME,' ')||' '||s.LAST_NAME AS FULL_NAME";
		break;
		
		case 'PARENTS':
			$field = 'ssm.STUDENT_ID AS PARENTS';
			$functions['PARENTS'] = 'makeParents';
		break;

		case 'MAIL_ADDRESS':
		case 'MAIL_CITY':
		case 'MAIL_STATE':
		case 'MAIL_ZIPCODE':
		case 'ADDRESS':
		case 'CITY':
		case 'STATE':
		case 'ZIPCODE':
			$field = 'a.'.$field;
		break;
		
		case 'CITY_STATE':
			$field = "a.CITY||', '||a.STATE AS CITY_STATE";
		break;
		
		case 'MAIL_CITY_STATE':
			$field = "a.MAIL_CITY||', '||a.MAIL_STATE AS MAIL_CITY_STATE";
		break;

		case 'ENTIRE_ADDRESS':
			$field = "a.ADDRESS||' '||a.CITY||', '||a.STATE||' '||a.ZIPCODE AS ENTIRE_ADDRESS";
		break;

		case 'ENTIRE_MAILING_ADDRESS':
			$field = "a.MAIL_ADDRESS||' '||a.MAIL_CITY||', '||a.MAIL_STATE||' '||a.MAIL_ZIPCODE AS ENTIRE_MAILING_ADDRESS";
		break;
		
		case 'SEM_GPA':
			$field = '(SELECT sgc.CUMULATIVE_GPA FROM STUDENT_GPA_CALCULATED sgc,SCHOOL_SEMESTERS m WHERE sgc.STUDENT_ID=ssm.STUDENT_ID AND sgc.MARKING_PERIOD_ID=m.MARKING_PERIOD_ID ORDER BY m.SYEAR DESC,m.SORT_ORDER DESC LIMIT 1) AS SEM_GPA';
			$functions['SEM_GPA'] = 'RoundGPA';
		break;
		case 'QTR_GPA':
			$field = '(SELECT sgc.CUMULATIVE_GPA FROM STUDENT_GPA_CALCULATED sgc,SCHOOL_QUARTERS m WHERE sgc.STUDENT_ID=ssm.STUDENT_ID AND sgc.MARKING_PERIOD_ID=m.MARKING_PERIOD_ID ORDER BY m.SYEAR DESC,m.SORT_ORDER DESC LIMIT 1) AS QTR_GPA';
			$functions['QTR_GPA'] = 'RoundGPA';
		break;
		case 'SEM_GPA':
			$field = '(SELECT sgc.CUMULATIVE_WEIGHTED_GPA FROM STUDENT_GPA_CALCULATED sgc,SCHOOL_SEMESTERS m WHERE sgc.STUDENT_ID=ssm.STUDENT_ID AND sgc.MARKING_PERIOD_ID=m.MARKING_PERIOD_ID ORDER BY m.SYEAR DESC,m.SORT_ORDER DESC LIMIT 1) AS SEM_GPA';
			$functions['SEM_WEIGHTED_GPA'] = 'RoundGPA';
		break;
		case 'QTR_GPA':
			$field = '(SELECT sgc.CUMULATIVE_WEIGHTED_GPA FROM STUDENT_GPA_CALCULATED sgc,SCHOOL_QUARTERS m WHERE sgc.STUDENT_ID=ssm.STUDENT_ID AND sgc.MARKING_PERIOD_ID=m.MARKING_PERIOD_ID ORDER BY m.SYEAR DESC,m.SORT_ORDER DESC LIMIT 1) AS QTR_GPA';
			$functions['QTR_WEIGHTED_GPA'] = 'RoundGPA';
		break;
		case 'SEM_CLASS_RANK':
			$field = '(SELECT sgc.CLASS_RANK||\'/\'||sgc.GRADE_TOTAL FROM STUDENT_GPA_CALCULATED sgc,SCHOOL_SEMESTERS m WHERE sgc.STUDENT_ID=ssm.STUDENT_ID AND sgc.MARKING_PERIOD_ID=m.MARKING_PERIOD_ID ORDER BY m.SYEAR DESC,m.SORT_ORDER DESC LIMIT 1) AS SEM_CLASS_RANK';
		break;
		case 'QTR_CLASS_RANK':
			$field = '(SELECT sgc.CLASS_RANK||\'/\'||sgc.GRADE_TOTAL FROM STUDENT_GPA_CALCULATED sgc,SCHOOL_QUARTERS m WHERE sgc.STUDENT_ID=ssm.STUDENT_ID AND sgc.MARKING_PERIOD_ID=m.MARKING_PERIOD_ID ORDER BY m.SYEAR DESC,m.SORT_ORDER DESC LIMIT 1) AS QTR_CLASS_RANK';
		break;
		case 'SEM_CREDITS':
			$field = '(SELECT SUM(CREDITS) FROM STUDENT_REPORT_CARD_GRADES WHERE CARRIES_CREDITS=\'Y\' AND STUDENT_ID=ssm.STUDENT_ID AND MARKING_PERIOD_ID IN ('.GetAllTerms('SCHOOL_SEMESTERS').')) AS SEM_CREDITS';
		break;
		case 'QTR_CREDITS':
			$field = '(SELECT SUM(CREDITS) FROM STUDENT_REPORT_CARD_GRADES WHERE CARRIES_CREDITS=\'Y\' AND STUDENT_ID=ssm.STUDENT_ID AND MARKING_PERIOD_ID IN ('.GetAllTerms('SCHOOL_QUARTERS').')) AS QTR_CREDITS';
		break;
		
		default:
			$date = DBDate();
			if(!$periods_RET)
				$periods_RET = DBGet(DBQuery("SELECT TITLE,PERIOD_ID,SHORT_NAME FROM SCHOOL_PERIODS ORDER BY SORT_ORDER"));
			foreach($periods_RET as $period)
			{
				if($field == 'PERIOD_'.$period['PERIOD_ID'])
				{
					if($period['SHORT_NAME'] && !$short_names_RET[$period['SHORT_NAME']])
						$short_names_RET[$period['SHORT_NAME']] = DBGet(DBQuery("SELECT PERIOD_ID FROM SCHOOL_PERIODS WHERE SHORT_NAME='".$period['SHORT_NAME']."'"));
					if(count($short_names_RET[$period['SHORT_NAME']]))
					{
						$periods_extra = " cp.PERIOD_ID IN (";
						foreach($short_names_RET[$period['SHORT_NAME']] as $id)
							$periods_extra .= "'".$id['PERIOD_ID']."',";
						$periods_extra = substr($periods_extra,0,-1);
						$periods_extra .= ") ";
					}
					$field = '(SELECT COALESCE(st.FIRST_NAME,\' \')||\' \'||COALESCE(st.LAST_NAME,\' \')||COALESCE(\' - \'||cp.ROOM,\' \') FROM USERS st,SCHEDULE ss,COURSE_PERIODS cp WHERE ss.STUDENT_ID=ssm.STUDENT_ID AND cp.COURSE_PERIOD_ID=ss.COURSE_PERIOD_ID AND cp.TEACHER_ID=st.STAFF_ID AND '.$periods_extra.' AND (\''.$date.'\' BETWEEN ss.START_DATE AND ss.END_DATE OR \''.$date.'\'>=ss.START_DATE) ORDER BY ss.START_DATE LIMIT 1) AS PERIOD_'.$period['PERIOD_ID'];
				}			
			}
		
		break;
	}

	$field .= ',';
	return $field;
}

function makeLogHeader($student_id,$field)
{	global $_FOCUS;

	$log_RET = DBGet(DBQuery("SELECT ID,LOG_CHECKBOX,LOG_SELECT,LOG_DATE,LOG_TEXT1,LOG_TEXT2,LOG_TEXT3,LOG_TEXT4,LOG_NUMERIC,LOG_TEXTAREA FROM STUDENT_LOG_ENTRIES WHERE STUDENT_ID='".$student_id."' AND STUDENT_FIELD_ID='".substr($field,7)."' ORDER BY ID ASC"));
	$field = $_FOCUS['fields_RET'][substr($field,7)][1];
	$table = '<TABLE border=1>';
	$table .= '<TR>';
	if($field['LOG_CHECKBOX'])
	{
		$table .= '<TH>';
		$table .= $field['LOG_CHECKBOX_TITLE'];
		$table .= '</TH>';
	}
	if($field['LOG_SELECT'])
	{
		$table .= '<TH>';
		$table .= $field['LOG_SELECT_TITLE'];
		$table .= '</TH>';
	}
	if($field['LOG_DATE'])
	{
		$table .= '<TH>';
		$table .= $field['LOG_DATE_TITLE'];
		$table .= '</TH>';
	}
	if($field['LOG_NUMERIC'])
	{
		$table .= '<TH>';
		$table .= $field['LOG_NUMERIC_TITLE'];
		$table .= '</TH>';
	}
	for($i=1;$i<=5;$i++)
	{
		if($field['LOG_TEXT'.$i])
		{
			$table .= '<TH>';
			$table .= $field['LOG_TEXT'.$i.'_TITLE'];
			$table .= '</TH>';
		}
	}
	if($field['LOG_TEXTAREA'])
	{
		$table .= '<TH>';
		$table .= $field['LOG_TEXTAREA_TITLE'];
		$table .= '</TH>';
	}
	$table .= '</TR>';	
	foreach($log_RET as $row)
	{
		$table .= '<TR>';
		if($field['LOG_CHECKBOX'])
		{
			$table .= '<TD>';
			$table .= ($row['LOG_CHECKBOX']!='Y'?'N':'Y');
			$table .= '</TD>';
		}
		if($field['LOG_SELECT'])
		{
			$table .= '<TD>';
			$table .= $row['LOG_SELECT'];
			$table .= '</TD>';
		}
		if($field['LOG_DATE'])
		{
			$table .= '<TD>';
			$table .= ProperDate($row['LOG_DATE']);
			$table .= '</TD>';
		}
		if($field['LOG_NUMERIC'])
		{
			$table .= '<TD>';
			$table .= $row['LOG_NUMERIC'];
			$table .= '</TD>';
		}
		for($i=1;$i<=5;$i++)
		{
			if($field['LOG_TEXT'.$i])
			{
				$table .= '<TD>';
				$table .= $row['LOG_TEXT'.$i];
				$table .= '</TD>';
			}
		}
		if($field['LOG_TEXTAREA'])
		{
			$table .= '<TD>';
			$table .= $row['LOG_TEXTAREA'];
			$table .= '</TD>';
		}
		$table .= '</TR>';
	}
	$table .= '</TABLE>';

	return $table;
}

function RoundGPA($gpa)
{
	return round($gpa,3);
}

function makeSyear($syear)
{
	return $syear.((SystemPreferences('SYEAR_TITLE')=='YYYY-YYYY')?'-'.($syear+1):'');
}
?>
